package com.itheima.mapDemo1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();

        map.put("aaa1", "aaaa1");
        map.put("aaa2", "aaaa2");
        map.put("aaa3", "aaaa3");
        map.put("aaa4", "aaaa4");
        map.put("aaa5", "aaaa5");

        System.out.println("遍历方式2：键值对");

        /*
        * 遍历2：键值对
        * */
        Set<Map.Entry<String, String>> entries = map.entrySet();
        // 增强for
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
        System.out.println("---------------");
        // 迭代器
        Iterator<Map.Entry<String, String>> it = entries.iterator();
        while (it.hasNext()){
            Map.Entry<String, String> next_entry = it.next();
            System.out.println(next_entry.getKey() + "=" + next_entry.getValue());
        }
        System.out.println("---------------");
        // Lambda表达式
        entries.forEach(entry -> System.out.println(entry.getKey() + "=" + entry.getValue()));
    }
}
